package com.tm.d1_api_object;

import java.util.Arrays;
import java.util.Objects;

/**
 * Cloneable是一个标记接口 User类
 */
public class User  implements Cloneable{
    /**
     * 编号
     */
    private  int id;

    /**
     * 用户名
     */
    private String  name;

    /**
     * 密码
     */
    private String password;

    /**
     * 分数
     */
    private double[] scores;

    public User() {

    }

    public User(int id, String name, String password, double[] scores) {
        this.id=id;
        this.name=name;
        this.password=password;
        this.scores=scores;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public double[] getScores() {
        return scores;
    }

    public void setScores(double[] scores) {
        this.scores = scores;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", password='" + password + '\'' +
                ", scores=" + Arrays.toString(scores) +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return id == user.id && Objects.equals(name, user.name) && Objects.equals(password, user.password) && Arrays.equals(scores, user.scores);
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        User u2 = (User) super.clone();
         u2.scores = u2.scores.clone();
        return u2;
    }
}
